package com.cardetective.shopcar.page.activity.main

import android.os.Bundle
import androidx.annotation.DrawableRes
import com.android.basemvvm.BaseVMActivity
import com.blankj.utilcode.util.LogUtils

import com.cardetective.shopcar.databinding.ActivityMainBinding
import com.cardetective.shopcar.databinding.ItemBottomBarBinding

import com.gyf.immersionbar.ImmersionBar

import top.wangchenyan.common.widget.pager.CustomTabPager



class MainActivity : BaseVMActivity<MainViewModel, ActivityMainBinding>() {

    var applyCustom: CustomTabPager? = null

    override fun initView(savedInstanceState: Bundle?) {

    }

    override fun initData() {
        ImmersionBar.with(this).statusBarDarkFont(true).init()

        with(mBinding) {
            applyCustom = CustomTabPager(lifecycle, supportFragmentManager, viewPager2).apply {
                BottomNaviTab.ALL.onEach {
                    LogUtils.e("数据：${it.name}")

                    val itemTab = getTabItem(it.icon, it.name)
                    addFragment(it.fragment(), itemTab.root)
                }
                setScrollable(false)
                setOnTabEventListener(object : CustomTabPager.OnTabEventListener {
                    override fun onTabSelected(position: Int) {
                        super.onTabSelected(position)
                        LogUtils.i("onTabSelected, position: $position")
                    }
                })
                setup()
            }
        }

    }

    private fun getTabItem(@DrawableRes icon: Int, text: String): ItemBottomBarBinding {
        val binding = ItemBottomBarBinding.inflate(layoutInflater, mBinding.tabBar, true)
        binding.ivIcon.setImageResource(icon)
        binding.tvTitle.text = text
        return binding
    }

}